/**
 * Created by GYL on 2018/7/25
 */
import React, { Component } from 'react';
import MyModal from '../../../components/common/MyModal';
import { Form, Row, Col, Input, message, Checkbox, DatePicker } from 'antd';

import config from "../../../config";
import style from "./AddModal.less";
const FormItem = Form.Item;

class AddModal extends Component {
    state = {

    };
    componentDidMount() {
        let t = this;
    };
    // modal保存
    onModalSave = () => {
        this.props.form.validateFieldsAndScroll((err, val) => {
            if (!err) {
                this.props.onModalSave(val, this.props.type)
            }
        });
    };
    // 筛选条件组件change事件
    getChangeValue(value, e) {
        let t = this;
        let params = {};
        params[value] = e.target.value;
        t.setState({ params });
    }
    onCheckbox(value, e) {
        let t = this;
        let params = {};
        params[value] = e.target.value;
        t.setState({ params });
    }
    render() {
        let t = this;
        let { getFieldDecorator } = t.props.form;
        let arr = this.props.AirArr
        return (
            <div>
                <MyModal
                    {...t.props}

                    width={500}
                    onModalSave={t.onModalSave}>
                    <Form>
                        <Row gutter={48} >
                        {
                                arr.map((item, index) => {
                                    if (item.type == 'input') {
                                        return (
                                            <Col style={{ marginBottom: 5 }} span={24}><span style={{marginRight:10}}>{item.name} :  </span>
                                                {
                                                    getFieldDecorator(item.paramName, {
                                                        initialValue: item.initialValue ? item.initialValue : '',
                                                        rules: item.rules || null
                                                    })(
                                                        <Input onChange={t.getChangeValue.bind(t, item.paramName)} size="small" style={item.style}
                                                            placeholder={item.placeholder} disabled={item.disabled} style={{ width: item.width?item.width:"100px" }} />
                                                    )
                                                }
                                            </Col>
                                        )
                                    } else if (item.type === 'datePicker') {
                                        let disabled = item.disabledDate ? disabledDate : null;
                                        return (
                                            <Col style={{ marginBottom: 5 }} span={24}><span style={{marginRight:10}}>{item.name} :  </span>

                                          {
                                                    getFieldDecorator(item.paramName, {
                                                        initialValue: item.initialValue ? item.initialValue : null
                                                    })(
                                                        <DatePicker size={config.size} format="YYYY-MM-DD HH:mm" disabledDate={disabled} disabled={item.disabled} />
                                                    )
                                                }

                                            </Col>
                                        )
                                    }


                                })
                            }
                        </Row>

                    </Form>
                </MyModal>
            </div>
        )
    }
}
export default Form.create()(AddModal);
